##
##    This file is part of Metrix.
##
##    Metrix is free software: you can redistribute it and/or modify
##    it under the terms of the GNU General Public License as published by
##    the Free Software Foundation, either version 3 of the License, or
##    (at your option) any later version.
##
##    Metrix is distributed in the hope that it will be useful,
##    but WITHOUT ANY WARRANTY; without even the implied warranty of
##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##    GNU General Public License for more details.
##
##    You should have received a copy of the GNU General Public License
##    along with Metrix.  If not, see <http://www.gnu.org/licenses/>.
##

class CreateIncidentes < ActiveRecord::Migration
  def self.up
	execute 'SET FOREIGN_KEY_CHECKS=0 '

    create_table :incidentes do |t|
		t.column "descripcion", :text
		t.column "tipo_incidente", :string
		t.column "severidad", :string
		t.column "estado", :string
		t.column "costo", :integer #en horas
		t.column "fecha_apertura", :date
		t.column "fecha_asignacion", :date
		t.column "fecha_correccion", :date
		t.column "fecha_cierre", :date
		t.column "creador_id", :integer
		t.column "asignado_id", :integer
		t.column "version_id", :integer
    end
	add_index "incidentes", ["creador_id"], :name => "fk_incidentes_creador"
    add_index "incidentes", ["asignado_id"], :name => "fk_incidentes_asignado"

    execute 'ALTER TABLE incidentes ADD CONSTRAINT fk_incidentes_creador FOREIGN KEY (creador_id) REFERENCES recursos(id) '
	execute 'ALTER TABLE incidentes ADD CONSTRAINT fk_incidentes_asignado FOREIGN KEY (asignado_id) REFERENCES recursos(id) '
  end

  def self.down
    drop_table :incidentes
  end
end
